﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Models.WebSite_HaiSheng;
using WebSite_HaiSheng;
using Utilities;
using Telerik.Web.Mvc;
using System.Web.Security;


namespace WebSite_HaiSheng.Controllers
{
    //[ManagerRequired(Roles = "Manager,Administrator", Order=2)]
    public class ArticleController : Controller
    {
        public ViewResult Index()
        {
            
            return View(CH.GetAllData<Article>());
        }

 
        public ActionResult AjaxArticleIndex()
        {
            return new DataJsonResult<Article>() { Data=CH.GetAllData<Article>()};
        }

        public ViewResult Details(int id)
        {
            return View(CH.GetDataById<Article>(id));
        }

        public ActionResult Create()
        {
            return View();
        } 

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Create(Article article)
        {
            if (ModelState.IsValid)
            {
                CH.Create<Article>(article);
                return RedirectToAction("Index");  
            }
            return View(article);
        }
 
        public ActionResult Edit(int id)
        {
            return View(CH.GetDataById<Article>(id));
        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Edit(Article article)
        {
            if (ModelState.IsValid)
            {
                CH.Edit<Article>(article);
                return RedirectToAction("Index");
            }
            return View(article);
        }
 
        public ActionResult Delete(int id)
        {
            return View(CH.GetDataById<Article>(id));
        }

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            CH.Delete<Article>(id);
            return RedirectToAction("Index");
        }
    }
}